import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class SwitchPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Switch"),
      ),
      body: Switch1_Widget(),
    );
  }
}

class Switch1_Widget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _Switch1_Widget_State();
  }
}

class _Switch1_Widget_State extends State<Switch1_Widget> {
  bool _switchSelect = true;
  bool? _checkboxSelect = true;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Switch(
            value: _switchSelect, //当前状态
            onChanged: (value) {
              //重新构建页面
              setState(() {
                _switchSelect = value;
              });
            }),
        Checkbox(
            value: _checkboxSelect,
            tristate: true,
            activeColor: Colors.red,
            onChanged: (value) {
              setState(() {
                _checkboxSelect = value;
              });
            })
      ],
    );
  }
}
